package com.qf.web.service.impl;

import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.ResultCode;
import com.qf.web.common.request.BannerRequestParams;
import com.qf.web.entity.Banner;
import com.qf.web.mapper.BannerMapper;
import com.qf.web.service.BannerService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zhangwei
 * yum
 */
@Service
public class BannerServiceImpl implements BannerService {
    @Resource
    private BannerMapper bannerMapper;

    @Override
    public int add(BannerRequestParams banner) {
        Banner bannerEntity = new Banner();
        /**
         * 第一个参数有值  第二个没值
         */
        BeanUtils.copyProperties(banner, bannerEntity);
        int count = bannerMapper.insert(bannerEntity);
        if (count > 0) {
            return count;
        } else {
            throw new ServiceException(ResultCode.ERROR);
        }
    }
}
